package com.luoboduner.moo.tool.util.vm;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.AnnotationDeclaration;
import com.github.javaparser.ast.body.AnnotationMemberDeclaration;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
/**
 * @author Liutime
 */
public class VelocityUtitl {
  public static String gen(String javaCode,String vm,String type){
    JavaParser.ClassInfo classInfo = JavaParser.parseController(javaCode);

    /**
     * 初始化velocity
     */
    VelocityInitializer.initVelocity();
    VelocityContext context = new VelocityContext();

    /**
     * 获取GenTable的属性名称与属性值
     */
    context.put("e", classInfo);
    context.put("ename", classInfo.name);


    StringWriter writer = new StringWriter();
    Velocity.evaluate(context, writer , "StringTemplate", vm);

    return writer.toString();
  }
}


/*

import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.comments.JavadocComment;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.expr.MemberValuePair;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


 */